package com.luo

import com.luo.test.domain.Student
import com.mysql.jdbc.jdbc2.optional.MysqlDataSource
import wangzx.scala_commons.sql._
import org.springframework.stereotype.Repository


@Repository
object JdbcRepo {

  val dataSource = {

      val ds = new MysqlDataSource
      ds.setURL(s"jdbc:mysql://127.0.0.1:3306/study?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull")
      ds.setUser("root")
      ds.setPassword("123456")
      ds
  }

  def queryAllStudents(): List[Student] = {
    dataSource.rows[Student]("select id,name,sex,chiness,math,english,classes from t_student")
      .map(x => Student(x.id, x.name,  x.sex, x.chiness, x.math, x.english , x.classes))
  }
}
